﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EBA.IoC
{
    /// <summary>
    /// 注入容器
    /// </summary>
    public interface IContainer
    {
        /// <summary>
        /// 默认<see cref="ILifetimeManager"/>
        /// </summary>
        ILifetimeManager LifetimeManager { get; set; }

        /// <summary>
        /// 通过<seealso cref="System.ComponentModel.Composition.ExportAttribute"/>，<seealso cref="System.ComponentModel.Composition.ImportAttribute"/>,<seealso cref="System.ComponentModel.Composition.ImportManyAttribute"/>,<seealso cref="System.ComponentModel.Composition.ImportingConstructorAttribute"/>和<see cref="ContainerConfiguration"/>生成的映射规则。
        /// </summary>
        AutowiredConventions Conventions { get; set; }

        /// <summary>
        /// 获取一个<typeparamref name="TExport"/>实例。
        /// </summary>
        TExport GetExport<TExport>(ILifetimeManager lifetimeManager = null);

        /// <summary>
        /// 获取一个名称为<paramref name="contractName"/>的<typeparamref name="TExport"/>实例。
        /// </summary>
        TExport GetExport<TExport>(string contractName, ILifetimeManager lifetimeManager = null);



        /// <summary>
        /// 获取一个<paramref name="exportType"/>实例。
        /// </summary>
        object GetExport(Type exportType, ILifetimeManager lifetimeManager = null);

        /// <summary>
        /// 获取一个名称为<paramref name="contractName"/>的<paramref name="exportType"/>实例。
        /// </summary>
        object GetExport(Type exportType, string contractName, ILifetimeManager lifetimeManager = null);

        /// <summary>
        /// 获取<typeparamref name="TExport"/>的所有实现的实例。
        /// </summary>
        IEnumerable<TExport> GetExports<TExport>(ILifetimeManager lifetimeManager = null);

        /// <summary>
        /// 获取名称为<paramref name="contractName"/>的<typeparamref name="TExport"/>的所有实现的实例。
        /// </summary>
        IEnumerable<TExport> GetExports<TExport>(string contractName, ILifetimeManager lifetimeManager = null);

        /// <summary>
        /// 获取<typeparamref name="TExport"/>的所有实现的实例，不区分名称。
        /// </summary>
        /// <typeparam name="TExport"></typeparam>
        /// <param name="lifetimeManager"></param>
        /// <returns></returns>
        IEnumerable<TExport> GetAllExports<TExport>(ILifetimeManager lifetimeManager = null);

        /// <summary>
        /// 获取<typeparamref name="exportType"/>的所有实现的实例。
        /// </summary>
        IEnumerable<object> GetExports(Type exportType, ILifetimeManager lifetimeManager = null);

        /// <summary>
        /// 获取名称为<paramref name="contractName"/>的<paramref name="exportType"/>的所有实现的实例。
        /// </summary>
        IEnumerable<object> GetExports(Type exportType, string contractName, ILifetimeManager lifetimeManager = null);

        /// <summary>
        /// 获取<param name="exportType">导出类型</param>的所有实现的实例，不区分名称。
        /// </summary>
        /// <param name="lifetimeManager"></param>
        /// <returns></returns>
        IEnumerable<object> GetAllExports(Type exportType, ILifetimeManager lifetimeManager = null);

        /// <summary>
        /// 获取一个<typeparam name="TExport">导出类型</typeparam>实例。
        /// </summary>
        bool TryGetExport<TExport>(out TExport export, ILifetimeManager lifetimeManager = null);

        /// <summary>
        /// 获取一个名称为<paramref name="contractName"/>的<typeparamref name="TExport"/>实例。
        /// </summary>
        bool TryGetExport<TExport>(string contractName, out TExport export, ILifetimeManager lifetimeManager = null);

        /// <summary>
        /// 获取一个<paramref name="exportType"/>实例。
        /// </summary>
        bool TryGetExport(Type exportType, out object export, ILifetimeManager lifetimeManager = null);

        /// <summary>
        /// 获取一个名称为<paramref name="contractName"/>的<paramref name="exportType"/>实例。
        /// </summary>
        bool TryGetExport(Type exportType, string contractName, out object export, ILifetimeManager lifetimeManager = null);

        /// <summary>
        /// 对指定<paramref name="instance"/>进行属性注入。
        /// </summary>
        void BuildUp<TEntity>(TEntity instance, ILifetimeManager lifetimeManager = null);
    }
}
